<?php

namespace App\Providers;

use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @return void
     */
    public function boot()
    {
        //

        parent::boot();
    }

    /**
     * Define the routes for the application.
     *
     * @return void
     */
    public function map()
    {
        $this->mapApiRoutes();

        $this->mapWebRoutes();

        //后台接口
        $this->mapAdminApiRoutes();
        //后台
        $this->mapAdminRoutes();
        //通知api （靠api路由顺序应在前）
        $this->mapNoticeApiRoutes();
        //通知模块
        $this->mapNoticeRoutes();

    }

    /**
     * Define the "admin api" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapAdminApiRoutes(){
        Route::group([
            'prefix'=>'adminApi',
            'middleware' => 'admin',
            'namespace' => 'App\Http\Controllers\AdminApi',
        ], function ($router) {
            require base_path('routes/adminApi.php');
        });
    }

    /**
     * Define the "admin" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapAdminRoutes(){
        Route::group([
            'prefix'=>'admin',
            'middleware' => 'admin',
            'namespace' => 'App\Http\Controllers\Admin',
        ], function ($router) {
            require base_path('routes/admin.php');
        });
    }


    /*
  * 定义一个noticeApi 路由
  */
    protected function mapNoticeApiRoutes(){
        Route::group([
            'prefix'=>'noticeApi',
            'middleware'=>'admin',
            'namespace'=>'App\Http\controllers\NoticeApi',
        ],function($router){
            require base_path('routes/noticeApi.php');
        });
    }

    /*
     * 定义一个notice 路由
     */
    protected function mapNoticeRoutes(){
        Route::group([
            'prefix'=>'notice',
            'middleware'=>'admin',
            'namespace'=>'App\Http\controllers\Notice',
        ],function($router){
            require base_path('routes/notice.php');
        });
    }






    /**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes(){
        Route::middleware('web')
             ->namespace($this->namespace)
             ->group(base_path('routes/web.php'));
    }

    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes()
    {
        Route::prefix('api')
             ->middleware('api')
             ->namespace($this->namespace)
             ->group(base_path('routes/api.php'));
    }
}
